package lib;

import com.mysql.cj.jdbc.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86186
 * Date: 2023-08-09
 * Time: 16:15
 */
public class Insert {
    public static void main(String[] args) throws SQLException {
        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource)dataSource).setURL("jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf8&useSSL=false&serverTimezone=UTC");
        ((MysqlDataSource)dataSource).setUser("root");
        ((MysqlDataSource)dataSource).setPassword("lmh041105666");

        Connection connection = (Connection) dataSource.getConnection();

        String sql = "insert into student values(?,?);";
        PreparedStatement statement = connection.prepareStatement(sql);
        Scanner scanner = new Scanner(System.in);
        int id = scanner.nextInt();
        String name = scanner.nextLine();
        statement.setInt(1,id);
        statement.setString(2,name);

        int reult = statement.executeUpdate();


        statement.close();
        connection.close();
    }
}
